﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RVEAd.Models;

namespace RVEAd.Helpers
{
    public static class Common
    {
        public static bool IsAM(int id)
        {
            return id <= 2;
        }

        public static string GetIntervalById(int id)
        {
            switch (id)
            {
                case 0 :
                    return "AM1";
                case 1:
                    return "AM2";
                case 2:
                    return "AM3"; 
                case 3:
                    return "PM1";
                case 4:
                    return "PM2";
            }

            return string.Empty;
        }

        public static string TranslateDayName(DayOfWeek dayName)
        {
            switch (dayName)
            {
                case DayOfWeek.Friday:
                    return "V";
                    
                case DayOfWeek.Monday:
                    return "L";
                    
                case DayOfWeek.Saturday:
                    return "S";

                case DayOfWeek.Sunday:
                    return "D";

                case DayOfWeek.Thursday:
                    return "J";

                case DayOfWeek.Tuesday:
                    return "M";

                case DayOfWeek.Wednesday:
                    return "Mi";
            }

            return "";
        }

        public static List<DateTime> GetMonthDays(DateTime date)
        {
            var currentDate = date;
            int monthDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month);

            IEnumerable<DateTime> monthDates = Enumerable
                .Range(1, monthDays)
                .Select(d => new DateTime(currentDate.Year, currentDate.Month, d));

            List<DateTime> list = new List<DateTime>();

            foreach (var day in monthDates)
            {
                list.Add(day);
            }

            return list;
        }


        /// <summary>
        /// Working days includes Saturdays
        /// </summary>
        /// <returns></returns>
        public static List<DateTime> GetMonthWorkingDays(DateTime date)
        {
            var currentDate = date;
            int monthDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month);

            IEnumerable<DateTime> monthDates = Enumerable.Range(1, monthDays)
                .Select(d => new DateTime(currentDate.Year, currentDate.Month, d));

            List<DateTime> list = new List<DateTime>();

            foreach (var day in monthDates)
            {
                if (day.DayOfWeek != DayOfWeek.Sunday)
                {
                    list.Add(day);
                }
            }

            return list;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static int GetDaysNumberInMonth(DateTime date)
        {
            return GetMonthWorkingDays(date).Count;
        }

        private static List<MonthItem> monthsList;
        public static List<MonthItem> MonthsList
        {
            get
            {
                if (monthsList == null)
                {
                    monthsList = new List<MonthItem>()
                    {
                        new MonthItem { MonthText="Ianuarie" , MonthValue = 1 },
                        new MonthItem { MonthText="Februarie" , MonthValue = 2 },
                        new MonthItem { MonthText="Martie" , MonthValue = 3 },
                        new MonthItem { MonthText="Aprilie" , MonthValue = 4 },
                        new MonthItem { MonthText="Mai" , MonthValue = 5 },
                        new MonthItem { MonthText="Iunie" , MonthValue = 6 },
                        new MonthItem { MonthText="Iulie" , MonthValue = 7 },
                        new MonthItem { MonthText="August" , MonthValue = 8 },
                        new MonthItem { MonthText="Septembrie" , MonthValue = 9 },
                        new MonthItem { MonthText="Octombrie" , MonthValue = 10 },
                        new MonthItem { MonthText="Noiembrie" , MonthValue = 11 },
                        new MonthItem { MonthText="Decembrie" , MonthValue = 12 },
                    };
                }
                return monthsList;
            }
        }

        private static List<int> yearsList;
        public static List<int> YearsList
        {
            get
            {
                if (yearsList == null)
                {
                    yearsList = new List<int>();

                    for (int i = Config.StartYear; i <= Config.StopYear; i++)
                    {
                        yearsList.Add(i);
                    }
                }

                return yearsList;
            }
        }
    }
}
